package com.singzi.javaSenior.threads.timer;

import java.sql.Time;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        MyTask myTask = new MyTask();
        Timer timer = new Timer();
        System.out.println("当前时间：" + new Date().toString());
        timer.schedule(myTask, 1000,2000);
        Thread.sleep(10000);
        myTask.cancel();
    }
}
class MyTask extends TimerTask{

    @Override
    public void run() {
        System.out.println("运行了！ 时间为：" + new Date());

    }
}